package com.hhly.rabbitmq.spring.produce;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MQProducerImpl implements MQProducer {
    @Autowired
	private AmqpTemplate amqpTemplate;
    
	@Override
	public void sendDataToQueue(String queueKey, String message) {
		byte [] body= message.getBytes();
		MessageProperties properties = new MessageProperties();
		properties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
		//properties.setPriority(5);
		Message message2 = new Message(body,properties );
		amqpTemplate.send(queueKey,message2);
	}

	@Override
	public void sendDataToFanout(String exchange, String message) {
		amqpTemplate.convertAndSend(exchange, "", message);
	}

}
